|
|
|
|
|
|
|
CrystalReport1.DataFiles(0) = txtReportDBName ' set the database location
CrystalReport1.ReportFileName = txtReportName ' set the report location
CrystalReport1.CopiesToPrinter = txtCopies ' set the copies parm
'
' if it's going to a file
If cboFileTypes.ListIndex <> -1 Then
CrystalReport1.PrintFileType = cboFileTypes.ListIndex
CrystalReport1.PrintFileName = txtFileName
End If
'
On Error GoTo ReportErr ' set error trap
Kill txtFileName ' delete file if it's there
CrystalReport1.Action = 1 ' run report
On Error GoTo 0 ' turn off error trap
GoTo OKExit ' exit sub
'
' report any error you get
ReportErr:
If Err <> 53 Then ' skip file not found msg
'
' see if the error is from CRW
If CrystalReport1.LastErrorNumber <> 0 Then
cMsg = Str(CrystalReport1.LastErrorNumber)
cMsg = cMsg + ":" + CrystalReport1.LastErrorString
cTitle = "Crystal Reports Pro Error"
Else
'
' error was from VB
cMsg = Str(Err) + ":" + Error$(Err)
cTitle = "Visual Basic Error"
End If
'
' show the error # and text
MsgBox cMsg, 0, cTitle
End If
Resume Next
'
' end of this procedure
OKExit:
End Sub |
|
|
|
|
|
|
|
|
Finally, you need a bit of code behind the Exit button: |
|
|
|
|
|
|
|
|
Private Sub cmdExit_Click ()
Unload Me
End Sub |
|
|
|
|
|
|
|
|
Save the form as REPORT.FRM before you continue. You now need to make a few changes to the code behind the Print button on the CompanyMaster data entry form. You'll get rid of the Crystal Reports Pro Control on the main form because you have one on the Print Report dialog box now. You'll also set two parameters behind the Print button before you call the Print Report dialog box. |
|
|
|
|
|